<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/3/12
 * Time: 15:50
 */

namespace Home\Controller;

use Think\Controller;

class UserInfoController extends Controller
{

    public function _initialize()
    {
        header("content-type:text/html; charset=utf-8");
        $flag = session("?stuid");
        if (!$flag) {
            $this->error("未登录", U('Login/index'));
        }
    }

    public function index()
    {
        $stuid = session("stuid");

        $stuenroll = M("stuenroll");
        $UserInfo_one = $stuenroll->where("stuid={$stuid}")->select();
        $this->assign("UserInfo_one", $UserInfo_one);

        $teaminfo = M("teaminfo");
        $UserInfo_team = $teaminfo->where("stuid={$stuid}")->select();
        $this->assign("UserInfo_team", $UserInfo_team);

        $this->display();
    }

    public function remove()
    {
        $data["stuid"] = session("username");
        $data["enroll"] = I("enroll");

        $stuenroll = M("stuenroll");

        if ($stuenroll->where($data)->delete()) {
            $this->success("取消成功");
        } else {
            $this->error("取消失败");
        }
    }

    public function changePwd()
    {
        if (IS_POST) {
            $password = I("post.password");
            $StuInfo = D("StuInfo");
            $stuid = session("stuid");
            if ($StuInfo->where("stuid=$stuid")->setField("password", $password)) {
                $this->success("修改成功");
            } else {
                $this->error("修改失败");
            }
        } else {
            $this->display();
        }
    }
}